#from django
from django import forms
from django.utils.translation import ugettext_lazy as _


from goals.models import Goal

class GoalForm(forms.ModelForm):

    
    def __init__(self, *args, **kwargs):
        super(GoalForm, self).__init__(*args, **kwargs)
        self.is_update = False
    
    def clean(self):
        """ Do validation stuff. """
        # title is mandatory
        if 'title' not in self.cleaned_data:
            return
        # if a book with that title already exists...
      #  if not self.is_update:
      #      if Goal.objects.filter(title=self.cleaned_data['id']).count() > 0:
      #          raise forms.ValidationError(_("There is already this goal in the library."))
        return self.cleaned_data
    
    class Meta:
        model = Goal
        fields = ('title', 'description', 'deadline')

